package com.ruoyi.order.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.order.domain.TbOrderDetails;
import com.ruoyi.order.service.ITbOrderDetailsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 订单详情Controller
 * 
 * @author ruoyi
 * @date 2023-02-07
 */
@RestController
@RequestMapping("/details")
public class TbOrderDetailsController extends BaseController
{
    @Autowired
    private ITbOrderDetailsService tbOrderDetailsService;

    /**
     * 查询订单详情列表
     */
    @RequiresPermissions("order:details:list")
    @GetMapping("/list")
    public TableDataInfo list(TbOrderDetails tbOrderDetails)
    {
        startPage();
        List<TbOrderDetails> list = tbOrderDetailsService.selectTbOrderDetailsList(tbOrderDetails);
        return getDataTable(list);
    }

    /**
     * 导出订单详情列表
     */
    @RequiresPermissions("order:details:export")
    @Log(title = "订单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbOrderDetails tbOrderDetails)
    {
        List<TbOrderDetails> list = tbOrderDetailsService.selectTbOrderDetailsList(tbOrderDetails);
        ExcelUtil<TbOrderDetails> util = new ExcelUtil<TbOrderDetails>(TbOrderDetails.class);
        util.exportExcel(response, list, "订单详情数据");
    }

    /**
     * 获取订单详情详细信息
     */
    @RequiresPermissions("order:details:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbOrderDetailsService.selectTbOrderDetailsById(id));
    }

    /**
     * 新增订单详情
     */
    @RequiresPermissions("order:details:add")
    @Log(title = "订单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbOrderDetails tbOrderDetails)
    {
        return toAjax(tbOrderDetailsService.insertTbOrderDetails(tbOrderDetails));
    }

    /**
     * 修改订单详情
     */
    @RequiresPermissions("order:details:edit")
    @Log(title = "订单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbOrderDetails tbOrderDetails)
    {
        return toAjax(tbOrderDetailsService.updateTbOrderDetails(tbOrderDetails));
    }

    /**
     * 删除订单详情
     */
    @RequiresPermissions("order:details:remove")
    @Log(title = "订单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbOrderDetailsService.deleteTbOrderDetailsByIds(ids));
    }

    /**
     *我的订单详情
     */
    @DeleteMapping("orderDetails")
    public List<TbOrderDetails> orderDetails(@RequestParam("orderId") Integer orderId)
    {
            return tbOrderDetailsService.selectTbOrderIdDetailsList(orderId);
    }


}
